package com.atguigu.service.impl;

import com.atguigu.bean.Book;
import com.atguigu.bean.Page;
import com.atguigu.dao.BookDao;
import com.atguigu.dao.impl.BookDaoImpl;
import com.atguigu.service.BookService;

import java.util.List;

/**
 * @ Author:任留辉
 * @ Description:
 * @ Date:Created in 17:09 2021/3/16 0016
 */
public class BookServiceImpl implements BookService {
    private BookDao bookDao= new BookDaoImpl();
    /**
     *
     * @return
     */
   /* public List<Book> getBookList() {
        return bookDao.getBookList();
    }*/

    @Override
    public void deleteBook(int bookId) {
       bookDao.deleteBook(bookId);
    }

    @Override
    public void addBook(Book book) {
        bookDao.addBook(book);
    }

    @Override
    public Book getBookById(int bookId) {
        return bookDao.getBookById(bookId);
    }

    @Override
    public void updateBook(Book book) {
        bookDao.updateBook(book);
    }

 /*   @Override
    public List<Book> getBookPageNo(int pageNo, int pageSize) {
        return bookDao.getBookPageNo(pageNo,pageSize);
    }*/

    @Override
    public int getCount() {
        return bookDao.getCount();
    }

    @Override
    public Page<Book> getPage(Page<Book> page) {
        //获取总记录数
        int count = bookDao.getCount();
        //为page对象的属性赋值
        page.setCount(count);
        //根据page对象获取图书的分页信息
        List<Book> list = bookDao.getBookByPage(page);
        //为page对象的属性赋值
        page.setList(list);
        return page;
    }

    @Override
    public Page<Book> getPageByPrice(Page<Book> page, int minPrice, int maxPrice) {
        //获取价格区间下的总记录数
        int count = bookDao.getCountByPrice(minPrice,maxPrice);
        //为page对象的属性赋值
        page.setCount(count);
        //根据page对象和价格区间获取图书的分页信息
        List<Book> list = bookDao.getBookByPageAndPrice(page,minPrice,maxPrice);
        //为page对象的属性赋值
        page.setList(list);
        return page;
    }
}
